package vip.xiaonuo.bi.core.datasource.common;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import vip.xiaonuo.bi.core.datasource.config.ExtendParamConfig;
import vip.xiaonuo.bi.core.datasource.constans.DSconstant;

/**
 * 关系型数据库共同配置
 *  @author 顾育司
 *  @date  2023/12/15 12:09
 */
@Data
@ToString
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class RdbmsDataSourceConfig extends AbstractDataSourceConfig {

    /* 账号/用户名*/
    protected String username;

    /* 密码*/
    protected String password;



    /* 地址*/
    protected String url;

    /* 该连接写的数据库*/
    protected String schema ;

    /* JDBC 自定义参数, json 格式 */
    private String properties;

    public  AbstractDataSourceConfig buildDataSourceConfig(JSONObject dataJson, ExtendParamConfig configDTO){
        return   RdbmsDataSourceConfig
                .builder()
                // 构建基础配置
                .sourceType(getSourceType())
                .url(dataJson.getString(DSconstant.JDBC_URL))
                .username(dataJson.getString(DSconstant.USERNAME))
                .password(dataJson.getString(DSconstant.PASSWORD))
                // 存放额外配置
                .extendParamConfig(configDTO)
                .build();
    }

}
